package cn.edu.hust.youth.tzb.servlet.student;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.edu.hust.youth.tzb.service.StudentServiceImpl;


public class Modifypassword extends HttpServlet {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private static final String CONTENT_TYPE = "text/html; charset=GBK";
	protected void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
        response.setContentType(CONTENT_TYPE);
        PrintWriter out = response.getWriter();
        String oldpwd=request.getParameter("oldpwd");
        String firstpwd=request.getParameter("firstpwd");
        String studentid=request.getParameter("studentid");
        StudentServiceImpl ssi=new StudentServiceImpl();

        try {
          if( ssi.modifyPwd(studentid,oldpwd,firstpwd)){
              String target = "/student/modifypwd_success.jsp";
               RequestDispatcher rd = this.getServletContext().getRequestDispatcher(target);
               rd.forward(request,response);
          }
          else{
              String target = "/student/modifypwd_failed.jsp";
               RequestDispatcher rd = this.getServletContext().getRequestDispatcher(target);
               rd.forward(request,response);


          }

       } catch (Exception ex) {
           out.print(ex);
       }
	}

	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		doGet(req, resp);
	}

}
